package me.jtx.poplar.user.model.repository.impl;

import org.springframework.stereotype.Repository;

import me.jtx.poplar.core.data.BaseHibernateJpaRepository;
import me.jtx.poplar.user.model.entity.User;
import me.jtx.poplar.user.model.repository.UserRepository;

/**
 * User Repository implementation
 *
 * @author: Tong Huazhong(jsyzthz@gmail.com)
 * @copyright: &copy; 2016, Tong Huazhong
 */
@Repository
public class UserRepositoryImpl extends BaseHibernateJpaRepository<User, Long> implements UserRepository {

	@Override
	public User findByEmail(String email) {
		return (User) sessionFactory.getCurrentSession().createQuery("from User u where u.email = ?")
				.setString(0, email).uniqueResult();
	}

	@Override
	public User findByUsername(String username) {
		return (User) sessionFactory.getCurrentSession().createQuery("from User u where u.userName = ?")
				.setString(0, username).uniqueResult();
	}
}
